package com.hzncc.flowable_diboot.job;

import com.diboot.core.util.ContextHolder;
import com.diboot.scheduler.annotation.CollectThisJob;
import com.hzncc.flowable_diboot.service.report.impl.WeeklySummaryReportServiceImpl;
import lombok.extern.log4j.Log4j2;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.scheduling.quartz.QuartzJobBean;

import java.util.Map;

@DisallowConcurrentExecution
@CollectThisJob(
        name = "销售周报",
        cron = "0 0 12 ? * 6"
)
@Log4j2
public class WeeklyReportJob extends QuartzJobBean {
    @Override
    protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
        WeeklySummaryReportServiceImpl server = ContextHolder.getBean(WeeklySummaryReportServiceImpl.class);
        JobDataMap mergedJobDataMap = context.getMergedJobDataMap();
        Object currentWeek = mergedJobDataMap.get("currentWeek");
        try {
            server.sendWeeklyReportFile(Map.of("currentWeek", currentWeek));
        } catch (Exception e) {
            log.error(e);
            throw new RuntimeException(e);
        }
    }
}
